package org.zoomdev.zoom.ioc.test.shop.modules;

import org.apache.commons.lang3.ArrayUtils;
import org.zoomdev.zoom.common.filter.Filter;
import org.zoomdev.zoom.ioc.Ioc;
import org.zoomdev.zoom.ioc.annotations.Module;
import org.zoomdev.zoom.ioc.annotations.ModuleInit;
import org.zoomdev.zoom.ioc.impl.factories.ClassIocFactory;
import org.zoomdev.zoom.ioc.impl.factories.ModuleIocFactory;
import org.zoomdev.zoom.ioc.test.shop.services.ShopService;

@Module
public class ShopModule implements ModuleIocFactory.ModuleInitialize {


    public ShopModule() {

    }


    @ModuleInit
    public void init(ShopService shopService) {

    }

    @Override
    public void initialize(Ioc ioc) {
        ModuleIocFactory factory = ioc.fetch(ModuleIocFactory.class);
        ioc.replaceFactory(ClassIocFactory.class, new ClassIocFactory());
        factory.execute(ioc, new Filter<ModuleIocFactory.MethodInfo>() {
            @Override
            public boolean accept(ModuleIocFactory.MethodInfo value) {
                return ArrayUtils.contains(value.getParameterTypes(), ShopService.class);
            }
        });
    }
}
